package com.netafull;

import com.netafull.util.CloseUtil;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;

public class About extends Activity implements OnClickListener {
	ImageButton about_back;
	ImageButton mButton01, mButton02;
	
	boolean b = false;
	
	SharedPreferences sp;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.about);
		
		sp = getSharedPreferences("netafull",Context.MODE_PRIVATE);
		
		
		CloseUtil.activityList.add(About.this);
		
		about_back = (ImageButton) findViewById(R.id.about_button_left);
		mButton01 = (ImageButton) findViewById(R.id.info_button01);
		mButton02 = (ImageButton) findViewById(R.id.info_button02);
		about_back.setOnClickListener(this);
		mButton01.setOnClickListener(this);
		mButton02.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		System.out.println(v.getId());
		String model = android.os.Build.MODEL;
		switch (v.getId()) {
		case R.id.about_button_left:// 返回
			About.this.finish();
			break;
		case R.id.info_button01:// 与朋友分享
			b = true;
			Intent emailit = new Intent(Intent.ACTION_SEND);
			// 邮件标题
			emailit.putExtra(Intent.EXTRA_SUBJECT,
					getResources().getString(R.string.email_default_title));
			// 正文
			//String model = android.os.Build.MODEL;
			emailit.putExtra(Intent.EXTRA_TEXT,getResources().getString(R.string.info)+
					"\n"+model+getResources().getString(R.string.popwindow_email_content_xinghao));
			emailit.setType("text/plain"); // 纯文本则用text/plain的mime
			startActivityForResult(emailit, 1);
			break;
		case R.id.info_button02:// 提建议
			b = true;
			Intent emailit2 = new Intent(Intent.ACTION_SEND);
			// 收件人地址
			String[] receiver = {getResources().getString(R.string.email)};
			emailit2.putExtra(Intent.EXTRA_EMAIL, receiver);
			// 邮件标题
			emailit2.putExtra(Intent.EXTRA_SUBJECT,	getResources().getString(R.string.email_default_title2));
			// 正文
			//String model = android.os.Build.MODEL;
			emailit2.putExtra(Intent.EXTRA_TEXT, "\n\n" + model + getResources().getString(R.string.popwindow_email_content_xinghao));
			emailit2.setType("text/plain"); // 纯文本则用text/plain的mime
			startActivityForResult(emailit2, 1);
			break;
		}
	}
	@Override
	protected void onUserLeaveHint() {
		// TODO Auto-generated method stub
		super.onUserLeaveHint();
		if(!b){
			if(sp!=null){
				Editor editor = sp.edit();
				editor.clear();
				editor.commit();
			}
			System.out.println("开始销毁Activity");
			CloseUtil.closeActivity();
		}else{
			System.out.println("没有销毁Activity");
		}
	}
}
